package com.huanong.mapper;
/*
 *@Author:anran
 *@Date:2020/12/9
 *@Version 1.0
 */

import com.huanong.pojo.Order;
import com.huanong.pojo.vo.OrderVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderMapper {

    @Select("select * from orders")
    @Results({
            @Result(property = "product",column = "product_id",
            one = @One(select = "com.huanong.mapper.ProductMapper.queryProductById")),
            @Result(property = "person",column = "person_id",
            one = @One(select = "com.huanong.mapper.PersonMapper.queryById"))
    })
    List<Order> queryOrder();

    @Select("select * from orders where osid=#{OsId}")
    @Results({
            @Result(property = "product",column = "product_id",
                    one = @One(select = "com.huanong.mapper.ProductMapper.queryProductById")),
            @Result(property = "person",column = "person_id",
                    one = @One(select = "com.huanong.mapper.PersonMapper.queryById"))
    })
    Order queryOrderById(@Param("OsId") Integer OsId);

    @Insert("insert into orders (ostime,osstatus,product_id,person_id) values(#{OsTime},#{OsStatus},#{productId},#{personId})")
    int addOrder(OrderVo order);

    @Delete("delete from orders where osid=#{OsId}")
    @Results({
            @Result(property = "product",column = "product_id",
                    one = @One(select = "com.huanong.mapper.ProductMapper.queryProductById")),
            @Result(property = "person",column = "person_id",
                    one = @One(select = "com.huanong.mapper.PersonMapper.queryById"))
    })
    int deleteOrder(@Param("OsId") Integer OsId);

    @Update("update orders set osstatus = ${OsStatus} where osid = ${OsId}")
    void updataOrderStauts(OrderVo order);

    @Select("select * from orders where person_id=#{psId}")
    @Results({
            @Result(property = "product",column = "product_id",
                    one = @One(select = "com.huanong.mapper.ProductMapper.queryProductById")),
            @Result(property = "person",column = "person_id",
                    one = @One(select = "com.huanong.mapper.PersonMapper.queryById"))
    })
    List<Order> queryOrderByUserid(@Param("psId") Integer psId);
}
